home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_309 / sksh / userman.doc < prev    next >
Text File  |  1992-05-06  |  82KB  |  2,575 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.                                    User's Guide to
  17.  
  18.                                         SKSH
  19.  
  20.                            A ksh-like Shell for the Amiga
  21.  
  22.                                      Version 1.3
  23.  
  24.  
  25.                                   (Copyright) 1989 
  26.  
  27.                                      Steve Koren
  28.  
  29.                                    January 2, 1990
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.           Table of Contents
  74.  
  75.                Introduction......................................3
  76.                Copyright Notice and Other Legal Stuff............4
  77.                A Brief History of Unix Shells....................5
  78.                SKsh Syntax.......................................6
  79.                Credits...........................................8
  80.                What SKsh is and is Not...........................9
  81.                The Rest of this Document.........................9
  82.                SKsh Basics: Executing Commands...................10
  83.                SKsh Basics: I/O Redirection......................11
  84.                SKsh Basics: Pipe Lines...........................12
  85.                SKsh Basics: Strings and Variables................13
  86.                SKsh Basics: Parameter Substitution...............15
  87.                SKsh Basics: Wildcards............................16
  88.                Using SKsh Aliases................................17
  89.                Using SKsh Functions..............................18
  90.                Function, Alias, Builtin Priority.................20
  91.                SKsh Command Substitution.........................21
  92.                Control Structures: if-then-elif-else-fi..........23
  93.                Control Structures: while-do-done.................24
  94.                Control Structures: for-do-done...................25
  95.                Test Expressions..................................26
  96.                Sub-Shell Execution...............................28
  97.                File Name Mapping.................................29
  98.                SKsh Scripts......................................30
  99.                Command Line Editing and History..................31
  100.                Filename Completion...............................35
  101.                Index to Users's Guide............................37
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.           SKSH Amiga Shell             Page 2                 User's Guide
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.           Introduction
  140.  
  141.             SKsh (Amiga-shell) is a shell  designed  for  the  Amiga  which
  142.             closely  duplicates  functionality  of  ksh or sh in Unix1.  It
  143.             is designed for programmers and other  expert  users  who  feel
  144.             limited  by  the  Amiga's  native  shell   environment.    SKsh
  145.             provides a very powerful environment; however, it  is  not  for
  146.             casual workbench users who want a "point and click" interface.
  147.  
  148.             SKsh provides a large number of features, some  of  which  have
  149.             not been previously available in Amiga shells:
  150.  
  151.                  *  Command substitution (using either  backtick  or  $(  )
  152.                     notations)
  153.  
  154.                  *  Shell functions with parameters
  155.  
  156.                  *  Aliases
  157.  
  158.                  *  Local variables, local functions, and local aliases
  159.  
  160.                  *  Powerful control structures and tests
  161.  
  162.                  *  emacs style line editing and history functions
  163.  
  164.                  *  I/O redirection and pipes
  165.  
  166.                  *  A large variety of built-in commands
  167.  
  168.                  *  Unix style wildcards
  169.  
  170.                  *  Unix filename conventions in AmigaDos (such as  ../file
  171.                     or ~/file)
  172.  
  173.                  *  Filename completion using <esc><esc> or tab
  174.  
  175.                  *  Coexistence with scripts from other shells
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.           1_____________________Unix is a trademark of AT&T.
  192.  
  193.  
  194.  
  195.           SKSH Amiga Shell             Page 3                 User's Guide
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.           Copyright Notice and Other Legal Stuff
  206.  
  207.             This software is copyright 1989 Steve Koren.  It is not  public
  208.             domain; however, it is freely distributable, provided  that  it
  209.             is not sold for profit  without  the  written  consent  of  the
  210.             author.  It may be included in compilations  of  public  domain
  211.             software, freely distributable software, and shareware  without
  212.             written consent of the author provided that no more than  $7.00
  213.             US 1989 dollars are charged for distribution and disk  handling
  214.             overhead.
  215.  
  216.             This and all included documents and works  are  also  copyright
  217.             1989 Steve Koren, and are included in the terms  of  the  above
  218.             paragraph.
  219.  
  220.             Any code included with this software may  be  freely  modified.
  221.             However, further distribution  of  this  modified  software  is
  222.             restricted  to  the  condition  that  a  notice  of  the  exact
  223.             modifications be clearly included with the documentation.   The
  224.             existing documentation may not be modified, only  appended  to.
  225.             The sole exception to this rule is that the  documentation  may
  226.             be translated to other languages and the original omitted.
  227.  
  228.             The porting of  this  software  to  other  computers  than  the
  229.             Commodore Amiga is permitted.
  230.  
  231.             The author of this software does  not  not  officially  support
  232.             it.  It is provided in the hope that it  will  be  useful,  but
  233.             since it is free, no guarantees of any kind are  provided,  and
  234.             you, the user, accept responsibility for its use.
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.           SKSH Amiga Shell             Page 4                 User's Guide
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.           A Brief History of Unix Shells
  272.  
  273.             Unix has, for a  long  time,  had  two  standard  shells.   csh
  274.             provides a programmable shell, and it is favored by  some  Unix
  275.             users because it also provides limited mechanisms  for  history
  276.             and command editing.   This  editing  is  cumbersome,  however,
  277.             using notations like this:
  278.  
  279.                   % ^echo^ls -l
  280.  
  281.             to edit lines.
  282.  
  283.             sh  provides  a  more  powerful   and   intuitive   programming
  284.             environment  than  csh, so it is preferred for writing scripts.
  285.             However, it lacks the editing and history facilities of csh.
  286.  
  287.             ksh is a newer Unix shell, and is fast  becoming  the  dominant
  288.             Unix shell.   It  provides  much  better  editing  and  history
  289.             mechanisms  than   csh,  and  a  more  powerful,  but  upwardly
  290.             compatible  programming environment than  sh.  This, it has the
  291.             advantages of both shells.
  292.  
  293.             SKsh on the Amiga is patterned closely after  ksh, although ksh
  294.             provides a much more powerful environment than does SKsh.
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.           SKSH Amiga Shell             Page 5                 User's Guide
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.           SKsh Syntax
  338.  
  339.             If  you  are  familiar  with  ksh or  sh programming under Unix
  340.             (tm), you will almost immediately become  proficient  at  SKsh.
  341.             Although SKsh  scripts  are  not  compatible  (except  in  some
  342.             specific cases) with those  of  sh or ksh, the syntax is nearly
  343.             identical, and many of the same  commands  are  present.   SKsh
  344.             operation will be discussed in much greater detail  later,  but
  345.             some examples are presented here,  mainly  for  those  who  are
  346.             already familiar with Unix shells.  If you  do  not  understand
  347.             these examples, this section can be safely ignored.
  348.  
  349.                A  simple  command is a  single  external  function,  alias,
  350.                builtin command, or  shell  function.   For  example,  "echo
  351.                foo" is a simple command, as is "a = 42" or "preferences".
  352.  
  353.                A  control  structure is a method  of  directing  execution.
  354.                Control  structures  can  contain  simple  commands,   other
  355.                control structures, pipe-lines, or sub-shells.
  356.  
  357.                     if [ $a -gt 0 ]
  358.                     then
  359.                         while [ $a -lt 10 ]
  360.                         do
  361.                            echo "A = $a"
  362.                            inc a
  363.                         done
  364.                     fi
  365.  
  366.                A  pipeline  is  a  sequence  of  simple  commands,  control
  367.                structures or sub-shells separated by pipe symbols.  A  pipe
  368.                symbol is a vertical bar ('|').  For example, the  following
  369.                is a pipeline:
  370.  
  371.                  for param in "these" are 'parameters' $boo
  372.                  do
  373.                     echo $param
  374.                  done | wc
  375.  
  376.                (notice the pipe symbol in  between  the  for-loop  and  the
  377.                word count command).  The input or output from  a  pipe  can
  378.                also be re-directed to or from a file.
  379.  
  380.                A  subshell  is  a  method  of  grouping  commands,  control
  381.                structures, pipes,  or  other  sub-shells.   Sub-shells  are
  382.                delimited by either parentheses:
  383.  
  384.                  (echo foo; echo bar)
  385.  
  386.                or curly-braces:
  387.  
  388.                  { which emacs; whence emacs }
  389.  
  390.                Sub-shells have certain specific uses,  and  the  two  forms
  391.  
  392.  
  393.           SKSH Amiga Shell             Page 6                 User's Guide
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.                above differ in their behaviour; this will be  explained  in
  404.                greater detail later.
  405.  
  406.                Command  substitution is a method for including  the  output
  407.                of a command as if it  was  typed  into  the  command  line.
  408.                Again, this will be explained in greater detail  later,  but
  409.                here are some examples using both the backtick (`)  and  the
  410.                $( ) syntax:
  411.  
  412.                  a=`basename foo:bar/not/file`
  413.  
  414.                or
  415.  
  416.                  echo $(expr length $(date -y))
  417.  
  418.                A  shell  function is similar to a script, but it is  stored
  419.                in the shell itself instead of a  file.   Thus,  it  can  be
  420.                accessed much faster  than  a  script.   Here  is  a  sample
  421.                function definition:
  422.  
  423.                  function param_count {
  424.                     echo "$# parameters were passed to this function,"
  425.                     echo "the second of which is $2"
  426.                  }
  427.  
  428.                Functions can contain local variables,  local  aliases,  and
  429.                even  local  functions,  as  well  as  any  combination   of
  430.                commands and control structures.  Functions can  call  other
  431.                functions and scripts, as well.
  432.  
  433.                An  alias is simply a way to save typing effort.   An  alias
  434.                can be used to take the place of a command and some  of  its
  435.                parameters so that the  command  is  easier  to  type.   For
  436.                example,
  437.  
  438.                  alias hist = 'history -e'
  439.  
  440.                There are other features as well that will  become  apparent
  441.                later.
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.           SKSH Amiga Shell             Page 7                 User's Guide
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470.           Credits
  471.  
  472.             SKsh was developed on and for the Commodore Amiga.
  473.  
  474.             SKsh was  implemented  and  debugged  entirely  with  Lattice C
  475.             5.04a.  Aside from a few bugs that cause incorrect code  to  be
  476.             generated at times, its a reasonably solid compiler.  It has  a
  477.             great debugger, too.
  478.  
  479.             SKsh was written and copyrighted by Steve Koren.
  480.  
  481.             This manual and the other included documents were  written  and
  482.             are copyrighted by Steve Koren.
  483.  
  484.             This manual was written  using  excellence! by MSS.  It did all
  485.             the cool stuff like the table of contents and index.
  486.  
  487.             SKsh is freely distributable.
  488.  
  489.             The SKsh parser was created using Amiga YACC.   This  yacc  was
  490.             ported to the Amiga by  Bill  Lee,  and  worked  great  once  I
  491.             recompiled it with larger tables to handle  the  SKsh  grammar.
  492.             I had expected to have problems with a micro based yacc, but  I
  493.             had none at all.
  494.  
  495.             Until SKsh was usable,  I  used  Matt  Dillon's  shell  version
  496.             3.01A during SKsh development.  I like that  shell  far  better
  497.             than the  normal  AmigaDos  environment.   It  provides  "real"
  498.             wildcards, and many  other  neat  things  the  normal  AmigaDos
  499.             environment does not.
  500.  
  501.             A bunch of people on Usenet and at  the  Cleveland  Area  Amiga
  502.             Users's Group have my  appreciation  for  putting  up  with  my
  503.             silly questions about invoking programs  on  the  Amiga  (which
  504.             turns out, unfortunately, not to be a trivial task).
  505.  
  506.             SKsh uses ARP  for  command  execution.   There  was  no  other
  507.             simple way to do it.
  508.  
  509.             I would  like  to  thank  everyone  who  made  suggestions  and
  510.             reported bugs.  These  people  are  too  numerious  to  mention
  511.             individually, but nonetheless have contributed to  SKsh  in  an
  512.             important way.
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.           SKSH Amiga Shell             Page 8                 User's Guide
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.           What SKsh is and is Not
  536.  
  537.             SKsh is a powerful alternative to  the  normal  Amigados  shell
  538.             environment.  This power comes at a price,  however.   SKsh  is
  539.             not a tiny program.  SKsh is currently about 70 K bytes;  small
  540.             by Unix standards but quite large for AmigaDos.
  541.  
  542.             SKsh provides a very similar environment to  that  found  under
  543.             the two Unix shells mentioned above.   It  does  not  claim  or
  544.             attempt to  provide  an  identical  environment.   Some  simple
  545.             scripts will run under SKsh or ksh, but this  fact  should  not
  546.             be depended on.  In many  cases,  ksh  provides  features  that
  547.             SKsh does not.  In some cases, SKsh provides features that  ksh
  548.             does not.  SKsh is, however, not a general purpose  programming
  549.             language - it is tailored to writing  scripts  that  use  other
  550.             programs and AmigaDos facilities.
  551.  
  552.             SKsh is not a speed daemon.  It would  have  been  possible  to
  553.             write a much faster programmable shell; however, it  would  not
  554.             have provided the ksh-like environment  that  SKsh  does.   The
  555.             SKsh script language is adequately fast for simple  tasks,  but
  556.             it is not suitable for complex calculations or algorithms.
  557.  
  558.             SKsh is  freely  distributable  software.   It  is  not  public
  559.             domain.   No  one  else  may  sell  SKsh  without  my   written
  560.             permission, except in  the  cases  detailed  in  the  copyright
  561.             notice.  You are, however, encouraged  to  distribute  SKsh  as
  562.             widely as possible.  It is completely free;  however,  with  my
  563.             other free software package (QRT, a  ray  tracer)  some  people
  564.             sent money anyway.  Any money I do receive from  SKsh  will  be
  565.             used for repair, maintenance, and upgrade of my  2000,  and  to
  566.             purchase upgrades to Lattice C and other Amiga software.
  567.  
  568.  
  569.           The Rest of this Document...
  570.  
  571.             The rest of this document is  an  intermediate  level  tutorial
  572.             for using SKsh.  It assumes that  you  are  familiar  with  the
  573.             basic concept and operation of a  command  interface,  such  as
  574.             the AmigaDos CLI.  If you  are  already  a  user  of  sh or ksh
  575.             under Unix, you will  probably  be  able  to  go  through  this
  576.             document very quickly.   I  do  recommend  that  you  read  it,
  577.             though, to see what SKsh does and does not do, and to see  what
  578.             differences there are between SKsh and the Unix shells.
  579.  
  580.             The SKsh reference manual  explains  each  command  in  greater
  581.             detail, although more concisely.  This document does  not  even
  582.             come close to covering every SKsh command.  It is mean to  give
  583.             you an understanding of the SKsh environment, so that  you  can
  584.             examine  the  reference  manual  for  information  on  specific
  585.             commands.
  586.  
  587.  
  588.  
  589.  
  590.  
  591.           SKSH Amiga Shell             Page 9                 User's Guide
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.           SKsh Basics: Executing Commands
  602.  
  603.             SKsh can, at the most simple level, be used like  the  AmigaDos
  604.             shell.  SKsh will display a prompt; exactly  what  this  prompt
  605.             says can be changed in a number of ways,  but  by  default  the
  606.             prompt  contains  the  current  working  directory, enclosed in
  607.             square brackets, followed by a  colon,  and  highlighted,  like
  608.             this:
  609.  
  610.                [dh0:usr/graphics]: _
  611.  
  612.             After you see this prompt, you may type commands.  It does  not
  613.             matter if these commands are external or internal to SKsh.
  614.  
  615.             Multiple commands on may be placed on a line if separated by a  
  616.             semicolon (';').  (Note: a semicolon does not  always  separate
  617.             commands.  For example, if the semicolon is quoted, it  becomes
  618.             part of a string).  In addition, any text after a '#' is  taken
  619.             to be a comment.
  620.  
  621.             Previous commands may be recalled and  edited  for  reuse.   In
  622.             addition, they may be searched for in the history  list.   This
  623.             will be explained in more  detail  later;  for  those  who  are
  624.             familiar with the 'emacs'  editor  from  FSF,  SKsh  duplicates
  625.             some of those keybindings.
  626.  
  627.             In SKsh, pressing control followed by 'c' (^c)  will  generally
  628.             abort whatever SKsh is currently doing and return  you  to  the
  629.             SKsh prompt.  For example, if you type 'sleep 6000', SKsh  will
  630.             wait for a very long time before returning to the prompt.   You
  631.             can press ^c to abort this command.  However, if  an  external,
  632.             non-SKsh command is executing, that  command  may  or  may  not
  633.             listen to ^c.
  634.  
  635.  
  636.  
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.           SKSH Amiga Shell            Page 10                 User's Guide
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666.  
  667.           SKsh Basics: I/O Redirection
  668.  
  669.             The input to or output from commands may be  redirected.   This
  670.             is accomplished by using Unix style operators:
  671.  
  672.                <  = redirect input
  673.                >  = redirect output
  674.                >> = redirect output, but append
  675.  
  676.             Any type of  command  or  statement  may  be  redirected.   For
  677.             example, the following are all equally valid:
  678.  
  679.                c:status > outfile
  680.  
  681.                sksh_script < infile >outfile
  682.  
  683.                while read in_line
  684.                do
  685.                   echo "Line was: $in_line"
  686.                done < input_file
  687.  
  688.                { echo; version; echo } >> out_file
  689.  
  690.             Note in the last two cases that  SKsh  statements  as  well  as
  691.             simple commands can use I/O redirection.  This  is  a  powerful
  692.             feature provided by Unix shells, but not, until now,  by  Amiga
  693.             shells.
  694.  
  695.  
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.           SKSH Amiga Shell            Page 11                 User's Guide
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732.  
  733.           SKsh Basics: Pipe Lines
  734.  
  735.             A pipe line is simply a series of  statements  separated  by  a
  736.             pipe symbol ('|').  For example,
  737.  
  738.                [dh0:]: echo "This is a pipe-line" | wc
  739.  
  740.             There can be any number of newlines after the pipe-symbol,  but
  741.             not  before  it  since  a  newline  typically  ends  a   simple
  742.             statement.  Thus, this is legal:
  743.  
  744.                [dh0:]: cat my_file.txt |
  745.                        head -20 |
  746.                        xd
  747.  
  748.             but this is not:
  749.  
  750.                [dh0:]: cat my_file.txt
  751.                        | head -20
  752.                        | xd
  753.  
  754.             since the newline after the 'cat...' terminates the command.
  755.  
  756.             Pipes are not limited to simple commands.   They  may  be  used
  757.             with any SKsh statement:
  758.  
  759.                [dh0:]: for a in a b c d e
  760.                >      do
  761.                >        echo "a = $a"
  762.                >      done | { read aa; read bb }
  763.                [dh0:]: echo $aa
  764.                     a = a
  765.  
  766.             SKsh was written to operate with  the  AmigaDos  pipe:  device,
  767.             with each branch of  the  pipe-line  executing  as  a  separate
  768.             process.   However,  some  limitations  in  the  way   AmigaDos
  769.             handles  processes  made   a   simple   thing   very   complex.
  770.             Therefore, the first release of SKsh uses  temporary  files  in
  771.             the pipe-line instead of true  inter-process  pipes  using  the
  772.             pipe: device.  Temporary file pipes are not  nearly  as  useful
  773.             as interprocess pipes; they are slower, and are limited by  the
  774.             free space on the device used to hold the files.   However,  at
  775.             the moment, the capability I  need  to  implement  interprocess
  776.             pipes is simply not there in a useable manner.  If  the  needed
  777.             capability ever shows up on the Amiga, SKsh is written to  take
  778.             advantage of it, and the code change to do this will be only  a
  779.             few lines.  Interprocess  pipes  using  the  pipe:  device  are
  780.             still usable in the normal manner using multiple  CLI  windows;
  781.             it is just not as convenient as the SKsh '|' pipe notation.
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.           SKSH Amiga Shell            Page 12                 User's Guide
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.  
  799.           SKsh Basics: Strings and Variables
  800.  
  801.             Strings and variables are basic to the operation of  SKsh.   A  
  802.             string  is  simply  a  sequence  of   non-special   characters,
  803.             optionally  surrounded  by  single  or  double   quotes.    For
  804.             example, this is a string:
  805.  
  806.                howdy
  807.  
  808.             A string which contains  white space or special characters must
  809.             be quoted.  The most common way to quote a string  is  to  use  
  810.             double quotes:
  811.  
  812.                "this string contains spaces and < special | symbols"
  813.  
  814.                "this string
  815.                 contains several
  816.                 newline characters"
  817.  
  818.             Strings can also be  surrounded  by  single quotes.  This has a
  819.             slightly  different  meaning;  see  the  section  on  variables
  820.             below.
  821.  
  822.             A string delimited by doubles quotes  can  contain  the  double
  823.             quote character itself by prefixing it with a backslash:
  824.  
  825.                "this string contains \" a double quote"
  826.  
  827.             Similarly, a single quoted string can contain  a  single  quote
  828.             if prefixed by a  backslash.   There  are  also  several  other
  829.             backslash escapes possible:
  830.  
  831.                \n   - newline character
  832.                \t   - tab character
  833.                \f   - form feed character
  834.                \\   - backslash character itself
  835.                \^   - the caret character
  836.  
  837.             Any control character can be included in a string by  prefixing
  838.             it with a caret (^).  For example, "^[" is escape.
  839.  
  840.             A  variable in SKsh is simply a storage place for strings.  Any
  841.             number of variables can be created.  Variables can be  assigned
  842.             values using the assignment operator:
  843.  
  844.                [dh0:]: my_var="contents of my_var variable"
  845.                [dh0:]: my_var2  = "more stuff"
  846.  
  847.             Note that  the  second  line  above,  with  spaces  around  the
  848.             assignment operator, is legal in SKsh, but  not  in  sh or ksh.
  849.             The SKsh assignment operator  is  upward  compatible  with  the
  850.             Unix shells.
  851.  
  852.             Variables can be retrieved by prefixing the variable name  with
  853.  
  854.  
  855.           SKSH Amiga Shell            Page 13                 User's Guide
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864.  
  865.             a '$'.  (In the examples below the results of the commands  are
  866.             indented for clarity).
  867.  
  868.                [dh0:]: echo $my_var
  869.                     contents of my_var variable
  870.                [dh0:]: echo $my_var2
  871.                     more stuff
  872.  
  873.             ("echo" is a command  that  simply  displays  its  parameters).
  874.             Variables  can  also  be  expanded  inside  of  double   quoted
  875.             strings:
  876.  
  877.                [dh0:]: echo "my_var = $my_var"
  878.                     my_var = contents of my_var variable
  879.  
  880.             However, variables are not expanded  inside  of  single  quoted
  881.             strings.  For example,
  882.  
  883.                [dh0:]: echo '$my_var'
  884.                     $my_var
  885.  
  886.             would not display the contents  of  the  variable  my_var,  but
  887.             rather would display the actual string $my_var,  including  the
  888.             '$' symbol.
  889.  
  890.             Variables may contain nearly any amount of  information.   They
  891.             typically are used to contain only small strings  and  numbers,
  892.             but if you wished you could store a whole file  in  a  variable
  893.             by saying:
  894.  
  895.                [dh0:]: big_var = $(cat my_file.txt)
  896.  
  897.             (the $( ) notation is simply a way to  execute  a  command  and
  898.             use the output of the command in another command.  It  will  be
  899.             discussed  in  more  detail  later.   The  above   command   is
  900.             equivalent to big_var  =  `cat  my_file`,  which  may  be  more
  901.             familiar   to   sh  users,  but  the  first  example  above  is
  902.             recommended).
  903.  
  904.  
  905.  
  906.  
  907.  
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.           SKSH Amiga Shell            Page 14                 User's Guide
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930.  
  931.           SKsh Basics: Parameter Substitution
  932.  
  933.             SKsh  normally  eliminates  white  space  (blanks, newlines and 
  934.             tabs)  from  between  parameters  to  commands.   For  example,
  935.             notice the spacing in the following command and response:
  936.  
  937.                [dh0:]: echo notice    the       spacing   here
  938.                     notice the spacing here
  939.  
  940.             If you wish to maintain the spacing above,  you  must  put  the
  941.             text in either a single or double quoted string,  which  causes
  942.             it to be treated as a single parameter:
  943.  
  944.                [dh0:]: echo 'notice    this   spacing'
  945.                     notice    this   spacing
  946.  
  947.             Even if the string echoed  comes  from  a  variable,  the  same
  948.             elimination of white space takes place:
  949.  
  950.                [dh0:]: a='some    text'
  951.                [dh0:]: echo $a
  952.                     some text
  953.  
  954.             If you wish to preserve  the  spacing,  you  must  enclose  the
  955.             variable in double quotes (remember, variables are expanded  in
  956.             double but not single quotes):
  957.  
  958.                [dh0:]: a='some    text'
  959.                [dh0:]: echo "$a"
  960.                     some    text
  961.  
  962.             (Note for advanced users: this action  is  actually  controlled
  963.             by a variable called the internal field separator, or IFS.)
  964.  
  965.             Internal  SKsh  commands  can  have  any  number of parameters,
  966.             (until you run out of memory).  External commands  are  limited
  967.             by the AmigaDos command  interpreter,  which  does  not  accept
  968.             commands longer than 256 characters in version 1.3.
  969.  
  970.  
  971.  
  972.  
  973.  
  974.  
  975.  
  976.  
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.           SKSH Amiga Shell            Page 15                 User's Guide
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.  
  996.  
  997.           SKsh Basics: Wildcards
  998.  
  999.             SKsh uses Unix style wildcard patterns  to  match  files.   The
  1000.             following characters have special meaning:
  1001.  
  1002.                *    - matches any number of characters, including zero
  1003.                ?    - matches exactly one character
  1004.                [ ]  - characters which enclose a character class
  1005.                !    - negate the pattern
  1006.  
  1007.             Since wildcards are expanded by SKsh, and not  by  the  command
  1008.             itself as in AmigaDos, they  may  be  used  with  any command -
  1009.             even a command such as 'echo'  which  does  not  normally  deal
  1010.             with files (try echo *).
  1011.  
  1012.             Here are some  examples  using  the  first  two  special  types
  1013.             above:
  1014.  
  1015.                a*f       matches 'af', 'abf', 'aazzzewerf', etc.
  1016.                a?f       matches 'abf', 'acf', but not 'af' or 'aaaf'
  1017.  
  1018.             The square brackets  above  are  used  to  define  a  character
  1019.             class.  A character class is simply way to  specify  an  exact  
  1020.             set  of  characters.  Character classes may  contain  either  a
  1021.             series  of  enumerated  characters, a range of characters, or a
  1022.             negation of any of the above.  For example,
  1023.  
  1024.  
  1025.                [abcz]    matches the character a, b, c, or z.
  1026.                [a-cv-z]  matches either a, b, c, v, w, y, x, or z.
  1027.                [!a-d]    matches any character except a, b, c, or d.
  1028.  
  1029.             Character classes may be combined with the * and ? wildcards:
  1030.  
  1031.                [a-c]*.c  matches any file starting with  a,  b,  or  c  and
  1032.                          ending with '.c'
  1033.  
  1034.             Wildcards are only expended  as  normal  parameters;  that  is,
  1035.             outside of quoted strings of any  sort.   Wildcards  also  have
  1036.             certain  other  uses  in  SKsh  besides  matching  files   (for
  1037.             example, see the 'match' or 'set' commands).
  1038.  
  1039.             Wildcards  do  not  have  to  be  used  in  only  the  filename
  1040.             component of a path.  For example, all  of  the  following  are
  1041.             valid wildcard patterns:
  1042.  
  1043.                sys:*/Format
  1044.                sys:System/Fo*
  1045.                mydir/*/*.c
  1046.                *.[hc]
  1047.  
  1048.             Wildcards are currently case-sensitive.
  1049.  
  1050.             (See also: File name mapping)
  1051.  
  1052.  
  1053.           SKSH Amiga Shell            Page 16                 User's Guide
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062.  
  1063.           Using SKsh Aliases
  1064.  
  1065.             An  'alias' in SKsh is simply a way to save  typing  time.   An
  1066.             alias can stand for any series  of  characters.   For  example,
  1067.             perhaps you enjoy seeing  the  version  number  of  SKsh.   You
  1068.             enjoy it so much, in fact, that you tire  of  typing  'version'
  1069.             over and over.  You can  define  an  alias,  called  'v',  that
  1070.             simply stands for the 'version' command:
  1071.  
  1072.                [dh0:]: alias v=version
  1073.                [dh0:]: v
  1074.                     SKsh Version 1.0, Copyright 1989 Steve Koren
  1075.  
  1076.             You can also include parameters  after  the  alias  call.   For
  1077.             example:
  1078.  
  1079.                [dh0:]: v -d
  1080.                     19:13:18 Oct 12 1989
  1081.  
  1082.             The alias command only looks at one  parameter  after  the  '='
  1083.             sign, so to include parameters in the alias, you  must  enclose
  1084.             the alias definition in quotes:
  1085.  
  1086.                [dh0:]: alias v='version -d'
  1087.                [dh0:]: v
  1088.                     19:13:18 Oct 12 1989
  1089.  
  1090.             To  obtain  a  list of aliases, simply use the alias command by
  1091.             itself:
  1092.  
  1093.                [dh0:]: alias
  1094.                     (big list of aliases)
  1095.  
  1096.             I left out the list of  aliases  above,  because  there  are  a
  1097.             large number supplied by SKsh itself.  One of  these  built  in
  1098.             aliases  is  the  unalias  command.   To  find  out  what   the
  1099.             definition of unalias is:
  1100.  
  1101.                [dh0:]: alias unalias
  1102.                     unalias      = unset -a
  1103.  
  1104.             So, the unalias command simply runs  the  command  'unset  -a'.
  1105.             Unalias is provided as a built in alias, however, since  it  is
  1106.             easier to remember than unset -a.  Unalias removes  any  number
  1107.             of alias definitions:
  1108.  
  1109.                [dh0:]: unalias v foo bar
  1110.  
  1111.             The above line would remove the alias definitions  of  v,  foo,
  1112.             and bar.
  1113.  
  1114.             Note that alias commands  may  be  used  just  like  any  other
  1115.             command, in scripts, functions, or substitution statements.
  1116.  
  1117.  
  1118.  
  1119.           SKSH Amiga Shell            Page 17                 User's Guide
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128.  
  1129.           Using SKsh Functions
  1130.  
  1131.             While aliases are limited to simple  text  substitution  uses,  
  1132.             functions are vastly more powerful.  Functions  provide  a  way
  1133.             to store SKsh programs within  SKsh  itself  instead  of  in  a
  1134.             file.  Here is an example function  that  SKsh  loads  when  it
  1135.             starts up.  Don't worry if you don't understand  everything  in
  1136.             the function definition; it will  be  explained  later  in  the
  1137.             programming sections.  For now, just notice that functions  can
  1138.             contain  any  SKsh  statements,  and  are  delimited  by  curly
  1139.             braces:
  1140.  
  1141.                function path {   # set or examine path
  1142.                     local comp;
  1143.  
  1144.                     if [ $# -eq 0 ]
  1145.                     then
  1146.                       echo "$PATH"
  1147.                     elif [ "$1" = '-add' -o "$1" = 'add' ]
  1148.                     then
  1149.                       shift
  1150.  
  1151.                       for comp in $* do
  1152.                          if [ $( expr index "$PATH," "$comp," ) -eq 0 ]
  1153.                          then
  1154.                            PATH = "$PATH,$comp"
  1155.                          fi
  1156.                       done
  1157.                     else
  1158.                       PATH="$1"
  1159.                     fi
  1160.  
  1161.                     export PATH
  1162.                }
  1163.  
  1164.             That function is one that defines a  "path"  command  in  SKsh.
  1165.             Functions may be used like any other command.  You do not  even
  1166.             have to know that they are functions.  For example,  the  above
  1167.             command, with no parameters, simply prints the path.  This  can
  1168.             be output to a file, a follows:
  1169.  
  1170.                [dh0:]: path > my_file
  1171.  
  1172.             The path function could also be used in other functions.   This
  1173.             provides a  very  powerful  mechanism  for  extending SKsh.  It
  1174.             will be particularly interesting for floppy users  who  do  not
  1175.             want to wait for slow script files.
  1176.  
  1177.             When SKsh functions  are  executed,  several  important  things
  1178.             happen.  All variables, functions, and aliases  defined  inside
  1179.             the  function  are   local  to  that  function  (although  this
  1180.             behaviour is changeable  in  several  ways  -  see  the  option
  1181.             command).  Hence:
  1182.  
  1183.  
  1184.  
  1185.           SKSH Amiga Shell            Page 18                 User's Guide
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194.  
  1195.                function outer {
  1196.                   function inner {
  1197.                      echo "my first parameter is $1"
  1198.                   }
  1199.                   inner $1
  1200.                }
  1201.  
  1202.             The  function  named  'inner'  can  only  be  used  within  the
  1203.             function named 'outer'.  You will notice also that  a  variable
  1204.             called $1 is  referenced,  but  not  set.   There  are  several
  1205.             variables that are automatically set by SKsh  when  a  function
  1206.             (or script) is invoked.  The most  useful  are  $0, $1, $2, $3,
  1207.             etc.  They are set to the  parameters passed into the function.
  1208.             Note that $0 is set to the function name itself:
  1209.  
  1210.                [dh0:]: function test1 {
  1211.                >    echo "0 = $0, 1 = $1, 2 = $2"
  1212.                > }
  1213.  
  1214.                [dh0:]: test1 foo bar
  1215.                     0 = test1, 1= foo, 2 = bar
  1216.  
  1217.             Also note the ">" marks to the left of the 2nd  and  3rd  lines
  1218.             of the function.  They  are  the  secondary SKsh prompt string,
  1219.             used when it expects more input.  You shouldn't type them.
  1220.  
  1221.             SKsh also sets  the  variable  '$#' to the number of parameters
  1222.             passed into the function:
  1223.  
  1224.                [dh0:]: function countp { echo "Number = $#" }
  1225.                [dh0:]: countp "this is all one" another param
  1226.                     Number = 3
  1227.  
  1228.             The  variable  '$*' is set to the  entire  parameter list.  For
  1229.             example:
  1230.  
  1231.  
  1232.                [dh0:]: function pparams { echo "Args = $*" }
  1233.                [dh0:]: pparams foo bar not
  1234.                     Args = foo bar not
  1235.  
  1236.             These standard variables  can  be  modified  with  the  'shift'
  1237.             command - see the documentation on that command for details.
  1238.  
  1239.             Any functions or aliases used within a  function  will  operate
  1240.             correctly even if they are defined after the  function  itself.
  1241.             (That is, they are bound dynamically  at  run-time).   This  is
  1242.             different than the ksh behavior.
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.           SKSH Amiga Shell            Page 19                 User's Guide
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260.  
  1261.           Function, Alias, Builtin Priority
  1262.  
  1263.             In SKsh, you can define a function or alias that overrides  the
  1264.             definition of a an SKsh  builtin  command  (such  as  the  echo
  1265.             statement).  SKsh will evaluate a  function  definition  before
  1266.             an alias with the same name, and  an  alias  before  a  builtin
  1267.             with the same name.  Thus, you can redefine the  internal  sksh
  1268.             commands.
  1269.  
  1270.             SKsh  still  provides  a  mechanism  to  access   the   builtin
  1271.             commands, even though  you  might  have  redefined  them.   The
  1272.             force keyword can be used  to  force the execution of a command
  1273.             as either a function, an alias, or  a  builtin.   For  example,
  1274.             say you have redefined the  sksh  date command with a function,
  1275.             as follows:
  1276.  
  1277.                [dh0:]: function date {
  1278.                >    echo 'The date command is not available today.'
  1279.                >    }
  1280.  
  1281.             Any future calls to the date command will  have  the  following
  1282.             result:
  1283.  
  1284.                [dh0:]: date
  1285.                     The date command is not available today.
  1286.  
  1287.             Suppose, however, that  you  really did wish to access the date
  1288.             builtin command, and not your function.  Use the  force keyword
  1289.             with the -b options (for force execution as a builtin):
  1290.  
  1291.                [dh0:]: force -b date
  1292.                     Sat Oct 14 11:13:27 1989
  1293.  
  1294.             This can be particularly  useful  when  you  wish  to  use  the
  1295.             original date command inside of your own.  Perhaps you wish  to
  1296.             define a date command which prints "The year is:"  followed  by
  1297.             the current year:
  1298.  
  1299.                [dh0:]: function date {
  1300.                >    echo -n 'The year is: '; force -b date -y
  1301.                >    }
  1302.                [dh0:]: date
  1303.                     The years is: 1989
  1304.  
  1305.             In this case, the force -b command must be used to  access  the
  1306.             builtin date command.   If  it  was  left  out,  the  new  date
  1307.             function would be used  instead,  calling  itself  recursively.
  1308.             SKsh would eventually detect this situation and issue an  error
  1309.             message, but it is not what the command was intended to do.
  1310.  
  1311.             The force keyword also accepts -f and -a parameters,  to  force
  1312.             execution as a function or alias.
  1313.  
  1314.  
  1315.  
  1316.  
  1317.           SKSH Amiga Shell            Page 20                 User's Guide
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325.  
  1326.  
  1327.           SKsh Command Substitution
  1328.  
  1329.             SKsh provides several mechanisms for capturing the output of  a
  1330.             statement for subsequent use.  The preferred method is  to  use
  1331.             the following syntax:
  1332.  
  1333.                $(command)
  1334.  
  1335.             SKsh will insert the output of the command as if it  was  typed
  1336.             in the SKsh command  line.   Consider  an  example.   The  sksh
  1337.             function 'basename' prints the file name part of a  path  name.
  1338.             For example,
  1339.  
  1340.                [dh0:]: basename sys:path/to/my/file
  1341.                     file
  1342.  
  1343.             Now, suppose you wish to obtain the file part of a path  string
  1344.             for use in an sksh function.  Normally the 'basename'  function
  1345.             copies the data to the screen.   You  want  to  have  it  in  a
  1346.             variable.  If the path you're interested in is in the  variable
  1347.             my_path:
  1348.  
  1349.                [dh0:]: bn = $(basename $my_path)
  1350.  
  1351.             The  variable  'bn'  will  contain  the  desired   information.
  1352.             Parameter substitution may be  nested.   For  example,  perhaps
  1353.             you wish to  obtain  the  length  in  characters  of  the  file
  1354.             portion of the path name:
  1355.  
  1356.                [dh0:]: len = $(expr length $(basename $my_path) )
  1357.  
  1358.             The  alternative  syntax  for   command   substitution   uses   
  1359.             backticks:
  1360.  
  1361.                [dh0:]: len = `basename $my_path`
  1362.  
  1363.             However, the first  notation  is  preferred  for  a  number  of
  1364.             reasons.  Using the backtick notation, SKsh  reads  the  entire
  1365.             substitution  command  as  one  token, or  set  of  characters.
  1366.             Tokens in SKsh are limited by the  parser  to  1024  characters
  1367.             (although strings and variables can be  of  any  length).   The
  1368.             parenthetical  notation  for  command   substitution   has   no
  1369.             restrictions on the length of the command enclosed -  it  could
  1370.             be an entire sksh program.  Also,  the  parenthetical  notation
  1371.             is faster than the backtick notation.
  1372.  
  1373.             You will discover that command substitution is  a  very  useful
  1374.             thing to have around.  One of  the  more  common  uses  is  the
  1375.             following:
  1376.  
  1377.                [dh0:]: my_program $(which abc)
  1378.  
  1379.             Here, my_program is a  program  which  uses  abc  in  some  way
  1380.             (perhaps executes it or edits it).  'abc' is  known  to  be  in
  1381.  
  1382.  
  1383.           SKSH Amiga Shell            Page 21                 User's Guide
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.  
  1391.  
  1392.  
  1393.             your SKsh path, but my_program does not know about SKsh  paths.
  1394.             The  which function in SKsh prints the full path name of a file
  1395.             in the search path, so the above command saves you from  having
  1396.             to remember and type the full path.
  1397.  
  1398.             Command  substitution  works  with  any  SKsh  statement.   For
  1399.             example:
  1400.  
  1401.                [dh0:]: a = $( for a in a b c
  1402.                >              do
  1403.                >                 echo "a: $a"
  1404.                >              done )
  1405.  
  1406.                [dh0:]: echo "$a"
  1407.                     a: a
  1408.                     a: b
  1409.                     a: c
  1410.  
  1411.             Note that the same variable was used both  inside  and  outside
  1412.             the command substitution.  This  is  ok,  since  the  statement
  1413.             list  inside  the  command  substitution  marks  is  completely
  1414.             evaluated before the assignment is made.
  1415.  
  1416.             Command substitution can also be used with  external  commands.
  1417.             Since external binaries do  not  support  command  substitution
  1418.             directly, SKsh stores the results in a temporary  file  in  the
  1419.             't:' directory.  When  finished,  SKsh  deletes  the  temporary
  1420.             file.  't:' should be assigned to a fast device, such as a  ram
  1421.             disk.  Actually, a subdirectory on the ram  disk  is  best,  so
  1422.             that SKsh's temporary files won't normally be seen.
  1423.  
  1424.  
  1425.  
  1426.  
  1427.  
  1428.  
  1429.  
  1430.  
  1431.  
  1432.  
  1433.  
  1434.  
  1435.  
  1436.  
  1437.  
  1438.  
  1439.  
  1440.  
  1441.  
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.           SKSH Amiga Shell            Page 22                 User's Guide
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458.  
  1459.           Control Structures: if-then-elif-else-fi
  1460.  
  1461.             SKsh  provides  a  set  of  control  structures  for  directing
  1462.             execution.  The most common of these is the  if-then-elif-else-
  1463.             fi statement.  It has several forms, but the  most  common  are
  1464.             these:
  1465.  
  1466.                if [ test expression ]
  1467.                then
  1468.                   statement
  1469.                   list
  1470.                fi
  1471.  
  1472.             The  test  expression is evaluated (more  on  test  expressions
  1473.             later), and if it is true,  the  statement  list  is  executed.
  1474.             The if statement can have an else part:
  1475.  
  1476.                if [ expression ]
  1477.                then
  1478.                   statement list
  1479.                else
  1480.                   statement list
  1481.                fi
  1482.  
  1483.             It can also have any number of else-if expressions:
  1484.  
  1485.                if [ expression ]
  1486.                then
  1487.                   stmt_list
  1488.                elif [ expression ]
  1489.                   stmt_list
  1490.                else
  1491.                   stmt_list
  1492.                fi
  1493.  
  1494.             Any valid SKsh statement list can be used inside the if:
  1495.  
  1496.                if [ $a -lt 10 ]
  1497.                then
  1498.                   a = 20
  1499.                   echo "a WAS less than ten, but now it's $a"
  1500.                fi
  1501.  
  1502.             An alternative form of the if statement can  be  used  to  test
  1503.             the return code from a command.  For example,
  1504.  
  1505.                if cmp -s file1 file2
  1506.                then
  1507.                   echo 'Files are the same'
  1508.                fi
  1509.  
  1510.             If the command following the if  keyword  returns  TRUE  (or  a
  1511.             zero  return  code),  the  if  statement  proceeds  as  if   an
  1512.             expression returned true.
  1513.  
  1514.  
  1515.           SKSH Amiga Shell            Page 23                 User's Guide
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.  
  1523.  
  1524.  
  1525.           Control Structures: while-do-done
  1526.  
  1527.             A while loop is simply a method for executing a statement  list
  1528.             as long as a certain given condition is true.  For example,
  1529.  
  1530.                while [ ! -d ram:my_dir ]
  1531.                do
  1532.                    sleep 10
  1533.                done
  1534.  
  1535.             which is an endless loop which waits until  a  given  directory
  1536.             exists (because another process created  it).   It  checks  for
  1537.             the existence of ram:my_dir  every  10  seconds.   (Again  test
  1538.             expressions will be explained in detail later).   As  with  if-
  1539.             then-else statements, a while statement can examine the  return
  1540.             code from a command.  A particularly useful while loop of  that
  1541.             form is the following:
  1542.  
  1543.                while read in_line
  1544.                do
  1545.                     echo "We read: $in_line"
  1546.                done < input_file
  1547.  
  1548.             That while loop executes as long as the  read  command  returns
  1549.             TRUE.  The read command returns FALSE upon reaching the end  of
  1550.             the input file, so the loop terminates then.  The entire  while
  1551.             loop has its input redirected from a given file.  In  practice,
  1552.             of course, the echo statement would be  replaced  by  the  code
  1553.             which accomplishes what you desire.  Here is  another  example,
  1554.             like the  above,  but  which  is  combined  with  SKsh  command
  1555.             substitution:
  1556.  
  1557.                my_var = $(  while read in_line
  1558.                             do
  1559.                                echo "We Read: $in_line"
  1560.                             done < input_file
  1561.                          );
  1562.  
  1563.             That is identical to the above loop, but saves the output in  a
  1564.             variable called my_var.   You  could  then  echo  "$my_var"  to
  1565.             retrieve this output.
  1566.  
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.           SKSH Amiga Shell            Page 24                 User's Guide
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.  
  1589.  
  1590.  
  1591.           Control Structures: for-do-done
  1592.  
  1593.             SKsh provides a for-do loop, but it differs from the for  loops
  1594.             provided with more most programming languages.   In  SKsh,  for
  1595.             loops are used to execute  a  series  of  statements  for  each
  1596.             parameters in a list.  For example,
  1597.  
  1598.                for my_param in abc def ghi
  1599.                do
  1600.                     echo "my_param = $my_param"
  1601.                done
  1602.  
  1603.             The statement list inside the for loop  is  executed  once  for
  1604.             each parameter, and each time, the variable 'my_var' is set  to
  1605.             the parameter in question.  That is,  the  first  time  through
  1606.             the loop, my_var  is  abc, the second time, def, and the third,
  1607.             ghi.   For  loops  are  useful  when  combined  with   wildcard
  1608.             patterns:
  1609.  
  1610.                for file in *.c
  1611.                do
  1612.                     cp $file dh0:backups/$file.bak
  1613.                done
  1614.  
  1615.             That loop executes once for each c code  file  in  the  current
  1616.             directory, copying the file to the  directory  dh0:backups  and
  1617.             adding a '.bak' extension  in  the  process.   After  you  gain
  1618.             experience with SKsh, you will become proficient  at  executing
  1619.             similar simple programs from the  command  line.   Even  though
  1620.             this loop is only four lines, it is quite useful.  In fact,  it
  1621.             could be shortened to one line  by  separating  the  components
  1622.             with ';'.  This loop has been extended to also copy .h files:
  1623.  
  1624.              for file in *.c *.h; do cp $file dh0:backups/$file.bak; done
  1625.  
  1626.             For loops  can  only  index parameters.  They cannot be used to
  1627.             count.  For that, you must use a while  loop  with  the  inc or 
  1628.             expr function.
  1629.  
  1630.  
  1631.  
  1632.  
  1633.  
  1634.  
  1635.  
  1636.  
  1637.  
  1638.  
  1639.  
  1640.  
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646.  
  1647.           SKSH Amiga Shell            Page 25                 User's Guide
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.  
  1655.  
  1656.  
  1657.           Test Expressions
  1658.  
  1659.             Test expression are used in if statements and while  statements
  1660.             to  test  a  given  expression  and  return   TRUE   or   FALSE
  1661.             appropriately.   Test  expressions  are  enclosed   in   square
  1662.             brackets   ('[   ]').   The  following   simple  operators  are
  1663.             available:
  1664.  
  1665.                -f fspec    TRUE if fspec exists and is a file
  1666.                -d fspec    TRUE if fspec exists and is a directory
  1667.                -s fspec    TRUE if fspec is a file and has a size of 0
  1668.                -r fspec    TRUE if fspec exists and is readable
  1669.                -w fspec    TRUE if fspec exists and is writable
  1670.                -x fspec    TRUE if fspec exists and is executable
  1671.                -S fspec    TRUE if fspec exists and the script bit is set
  1672.                -P fspec    TRUE if fspec exists and the pure bit is set
  1673.                -A fspec    TRUE if fspec exists and the archive bit is set
  1674.                -z string   TRUE if string has a length of 0
  1675.                -n string   TRUE if string has a non-zero length
  1676.                -m string   TRUE if string is the name of a mounted device
  1677.  
  1678.             The following comparison operators are available:
  1679.  
  1680.                n1 -eq n2   TRUE if n1 is numerically equal to n2
  1681.                n1 -ne n2   TRUE if n1 is numerically unequal to n2
  1682.                n1 -lt n2   TRUE if n1 is numerically less than n2
  1683.                n1 -gt n2   TRUE if n1 is numerically greater than n2
  1684.                n1 -le n2   TRUE if n1 is less than or equal to n2
  1685.                n1 -gt n2   TRUE if n1 is greater than or equal to n2
  1686.                s1 -ot s2   TRUE if the file s1 is older than the file s2
  1687.                s1 -nt s2   TRUE if the file s1 is newer than the file s2
  1688.                s1 = s2     TRUE if s1 is the same string as s2
  1689.                s1 != s2    TRUE if s1 is not the same string as s2
  1690.  
  1691.             Also, boolean operators are available:
  1692.  
  1693.                ! e1           TRUE if sub-expression e1 is false
  1694.                e1 -a e2       TRUE if e1 and e2 are both TRUE
  1695.                e1 -o e2       TRUE if e1 or e2 is TRUE
  1696.  
  1697.             Thus, the following expressions are all TRUE:
  1698.  
  1699.                [ 1 -lt 3 ]
  1700.                [ 3 -lt 2 -o 1 -lt 0 -o 3 -eq 3 ]
  1701.                [ -z '' ]
  1702.                [ -n "hi" ]
  1703.                [ ! -z "hi" ]
  1704.                [ a = 'a' ]
  1705.                [ 'xyz' != 'abc' ]
  1706.                [ -d 'c:' ]
  1707.                [ -f 'c:dir' -a -f 's:startup-sequence' ]
  1708.  
  1709.             The boolean  and  operator  has  a  high  precedence  than  the
  1710.             boolean -o operator.  Note also that test  expressions  do  not
  1711.  
  1712.  
  1713.           SKSH Amiga Shell            Page 26                 User's Guide
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.  
  1721.  
  1722.  
  1723.             print their result; they simple set the return code, which  can
  1724.             then be tested for.  A return code of zero  means  TRUE.   Here
  1725.             is an example usage of a test expression:
  1726.  
  1727.                i = 1
  1728.                while [ $i -le 10 ]
  1729.                do
  1730.                   echo "index variable = $i"
  1731.                   inc i
  1732.                done
  1733.  
  1734.             Here is another example:
  1735.  
  1736.                function my_func {
  1737.                   if [ $# -ne 3 ]
  1738.                   then
  1739.                      echo "This function requires exactly 3 parameters"
  1740.                      return
  1741.                   fi
  1742.                }
  1743.  
  1744.             The  inc command is simply  a  way  to  increment  a  variable.
  1745.             There are other ways do it, but inc is the fastest.
  1746.  
  1747.             Test expressions are related to, but  should  not  be  confused
  1748.             with, the expr command.
  1749.  
  1750.  
  1751.  
  1752.  
  1753.  
  1754.  
  1755.  
  1756.  
  1757.  
  1758.  
  1759.  
  1760.  
  1761.  
  1762.  
  1763.  
  1764.  
  1765.  
  1766.  
  1767.  
  1768.  
  1769.  
  1770.  
  1771.  
  1772.  
  1773.  
  1774.  
  1775.  
  1776.  
  1777.  
  1778.  
  1779.           SKSH Amiga Shell            Page 27                 User's Guide
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.  
  1787.  
  1788.  
  1789.           Sub-Shell Execution
  1790.  
  1791.             SKsh provides two mechanisms for grouping  commands;  they  are
  1792.             closely related both in behaviour and syntax, but differ in  an
  1793.             important way.
  1794.  
  1795.             If a series of  statements  is  grouped  within  either  curly-
  1796.             braces  '{ }' or parentheses '( )', that statement list is said
  1797.             to be executed within a sub shell.  For example:
  1798.  
  1799.                { echo foo; echo bar }
  1800.             and
  1801.                ( read foo; read bar )
  1802.  
  1803.             are both sub-shell statements.  Subshells group their  enclosed
  1804.             commands, so that all the commands within the subshell share  a
  1805.             common environment.  One use  for  this  is  to  give  all  the
  1806.             commands a common input or output.  For example:
  1807.  
  1808.                { c:status
  1809.                  echo "Done with status command"
  1810.                  c:dir
  1811.                  echo "Done with dir command"
  1812.                } > out_file
  1813.  
  1814.             The output of all the commands within the subshell  goes  to  a
  1815.             common file.  This works for input, as well:
  1816.  
  1817.                { read foo; read bar } < in_file
  1818.  
  1819.             If you tried  to  redirect  the  input  of  each  read  command
  1820.             separately,  both  'foo'  and  'bar'  would  contain  the  same
  1821.             information.  By using a sub-shell, the  reads  are  sequential
  1822.             from the input file.
  1823.  
  1824.             The parenthetical subshell syntax differs from the  above  form
  1825.             only in that any variables declared  within  the  subshell  are
  1826.             local.  For example,
  1827.  
  1828.                [dh0:] answer = 42; echo $answer
  1829.                     42
  1830.                [dh0:]: ( answer = 7; echo $answer )
  1831.                     7
  1832.                [dh0:]: echo $answer
  1833.                     42
  1834.  
  1835.             Notice that the answer variable is 42  both  before  and  after
  1836.             the subshell, but  is  7  within  it.   Because  this  type  of
  1837.             subshell allocates space for local variables,  the  first  form
  1838.             is both faster and uses  less  memory.   It  is  the  preferred
  1839.             form, unless you do in fact need local  variables.   (Functions
  1840.             and aliases declared  within  the  parenthetical  subshell  are
  1841.             local as well).
  1842.  
  1843.  
  1844.  
  1845.           SKSH Amiga Shell            Page 28                 User's Guide
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.  
  1853.  
  1854.  
  1855.           File Name Mapping
  1856.  
  1857.             When SKsh sees an unquoted file name, it  maps  the  file  name
  1858.             from a Unix style file name to an  AmigaDos  style  file  name.
  1859.             The Unix style has several advantages.  First and  foremost,  a
  1860.             single  dot ('.') can be used to specify  the  current  working
  1861.             directory. For example,
  1862.  
  1863.                [dh0:]: assign this_dir: .
  1864.                [dh0:]: HOME=.
  1865.  
  1866.             assigns  'this_dir'  (a  device)   to   the   current   working
  1867.             directory, and  then  sets  the  SKsh  home  directory  to  the
  1868.             current directory.  The dot can be used in  any  command,  such
  1869.             as 'cp' or 'mv', but it cannot  be  quoted  or  it  looses  its
  1870.             magic properties and becomes just a dot.  For example,
  1871.  
  1872.                [dh0:]: echo .
  1873.                     dh0:appl/excellence!/documents/SKSH
  1874.                [dh0:]: echo "."
  1875.                     .
  1876.  
  1877.             In  addition,  a  path  beginning  with  a  slash ('/') will be
  1878.             mapped by SKsh to be an AmigaDos absolute path name instead  of
  1879.             a relative path name.  For example,
  1880.  
  1881.                run lse /usr/src/SKsh/Parser.y
  1882.  
  1883.             really  edits  the  file  'dh0:usr/src/SKsh/Parser.y'  if   the
  1884.             current device is dh0:.  Also, SKsh maps  two  sequential  dots
  1885.             ('..') to be the parent  directory  of  the  current  directory
  1886.             (which in AmigaDos is specified with a slash):
  1887.  
  1888.                run emacs ../../my_file.c
  1889.  
  1890.             The file my_file.c  in  the  directory  two  levels  above  the
  1891.             current directory is loaded into emacs.
  1892.  
  1893.             A tilde ('~') can be used to specify the contents of  the  HOME
  1894.             variable.  For example, if HOME is 'sys:usr/src/SKsh',
  1895.  
  1896.                [dh0:]: echo ~/Parser.y
  1897.                     sys:usr/src/SKsh/Parser.y
  1898.  
  1899.             SKsh can be instructed not to perform this file  name  mapping.
  1900.             See the options command for details.
  1901.  
  1902.  
  1903.  
  1904.  
  1905.  
  1906.  
  1907.  
  1908.  
  1909.  
  1910.  
  1911.           SKSH Amiga Shell            Page 29                 User's Guide
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.  
  1919.  
  1920.  
  1921.           SKsh Scripts
  1922.  
  1923.             If a file containing SKsh commands is in the SKsh search  path,
  1924.             and has  its  script  bit  set,  SKsh  will  execute  the  file
  1925.             directly as if it was a binary file; there is no  need  to  use
  1926.             an  "execute"  or  other  special  command.    Normally,   SKsh
  1927.             executes the file  in  its  own  sub-shell.   Thus,  variables,
  1928.             functions, and aliases  defined  within  the  script  file  are
  1929.             local.  SKsh can also "source" files (execute them but  not  in
  1930.             a subshell).
  1931.  
  1932.             SKsh will happily co-exist with scripts from other shells.   If
  1933.             SKsh detects a file with the script bit set, it first  examines
  1934.             the first two characters of the file.   If  they  are  '#!'  or
  1935.             ';!' SKsh reads the rest of the first line,  appends  the  name
  1936.             of the script file, and passes the string  to  AmigaDos  to  be
  1937.             executed.  For example, on my system I have scripts from  SKsh,
  1938.             Matt Dillon's shell, and the AmigaDos  "execute"  command.   My
  1939.             scripts either begin with:
  1940.  
  1941.                #!sys:bin/shell
  1942.  
  1943.             if the script is to be executed by Matt's shell, or
  1944.  
  1945.                ;!c:execute
  1946.  
  1947.             if the file is an "execute" script.  Since the first  character
  1948.             is recognized by  the  appropriate  shell  as  a  comment,  the
  1949.             script runs fine, and SKsh  knows  to  pass  execution  to  the
  1950.             correct shell.  It is  important  that  there  are  no  leading
  1951.             blanks or newlines before the '#!' or ';!'; they  must  be  the
  1952.             first two characters of the file.  This mechanism can  be  used
  1953.             with any other Amiga shell that recognizes  '#'  or  ';'  as  a
  1954.             comment character.
  1955.  
  1956.             If the script bit is not set, SKsh will ignore the file  unless
  1957.             you explicitly use the 'source' command.  Also,  if  the  shell
  1958.             does not automatically exit after  executing  the  script,  you
  1959.             must include an explicit exit  statement  at  the  end  of  the
  1960.             script (such as with Matt Dillon's Shell).
  1961.  
  1962.             (Note: there seems to be a bug someplace with  using  ;!execute
  1963.             for AmigaDos execute scripts.  It seems that execute  sometimes
  1964.             returns before the script  has  finished  running,  and  things
  1965.             tend to get a bit confused.  I do not think  this  is  an  SKsh
  1966.             problem, since I run the execute command the same way as I  run
  1967.             anything else).
  1968.  
  1969.  
  1970.  
  1971.  
  1972.  
  1973.  
  1974.  
  1975.  
  1976.  
  1977.           SKSH Amiga Shell            Page 30                 User's Guide
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984.  
  1985.  
  1986.  
  1987.           Command Line Editing and History
  1988.  
  1989.             SKsh provides mechanisms for  recalling  and  editing  previous
  1990.             commands.  To obtain a  list  of  previous  commands,  use  the
  1991.             history command.   By  default,  SKsh  keeps  the  previous  32
  1992.             commands, although this number can be changed by  setting  the  
  1993.             HISTSIZE variable.
  1994.  
  1995.             In addition, command line editing  is  available  (but  can  be
  1996.             turned  off  -  see  the  options command).  The following keys
  1997.             have special meaning  (the  caret  mark  means  hold  down  the
  1998.             control key and press the following character):
  1999.  
  2000.                ^p or up arrow           - recall previous command
  2001.                ^n or down arrow         - recall next command
  2002.                ^b or left arrow         - move cursor left
  2003.                ^f or right arrow        - move cursor right
  2004.                ^m or return             - accept and execute current line
  2005.                ^a or shift-left         - move to beginning of line
  2006.                ^e or shift-right        - move to end of line
  2007.                ^k                       - kill to end of line
  2008.                ^l                       - redraw the current line
  2009.                ^d or delete key         - delete current character
  2010.                ^h or backspace          - delete previous character
  2011.                ^g                       - kill (erase) current line
  2012.                esc-f                    - move forward one word
  2013.                esc-b                    - move backward one word
  2014.                esc-d                    - delete the next word
  2015.                esc-backspace            - delete the previous word
  2016.                esc-< or shift-up        - move to first line in history
  2017.                esc-> or shift-down      - move to last line in history
  2018.                esc-esc or tab           - filename completion
  2019.                esc-=                    - List matching file names
  2020.                esc-*                    - Insert matching file names
  2021.                esc-.                    - Insert last param of prev line
  2022.                esc-/                    - Insert 'tail' of previous line
  2023.                ^r                       - reverse search for line
  2024.                ^o                       - execute line, move to next
  2025.                ^u                       - multiply next command by 4
  2026.                ^z                       - toggle insert/overstrike mode
  2027.                function keys            - insert defined text
  2028.  
  2029.             The basic  editing  commands  are  self  explanatory,  but  the
  2030.             others  may  not  be.   The   reverse search command is used to
  2031.             search for a string in the history list, and then  display  the
  2032.             line containing that string for further editing.  For  example,
  2033.             suppose your history list contained 4 lines, as follows:
  2034.  
  2035.                [dh0]: history
  2036.                     1: echo 'This is a test'
  2037.                     2: version
  2038.                     3: date
  2039.                     4: history
  2040.  
  2041.  
  2042.  
  2043.           SKSH Amiga Shell            Page 31                 User's Guide
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.  
  2051.  
  2052.  
  2053.             Then, at the SKsh prompt, type a substring  from  any  previous
  2054.             command:
  2055.  
  2056.                [dh0:]: test
  2057.  
  2058.             When  you  press  ^r,  the  most  recent  line  containing  the
  2059.             substring will be displayed and available for editing:
  2060.  
  2061.                [dh0:]: echo 'This is a test'
  2062.  
  2063.             This line can be edited, or accepted as is by pressing  return.
  2064.             If it is not the correct  line,  pressing  ^r  yet  again  will
  2065.             start  the  reverse  search  again  beginning  with  the   line
  2066.             previous to the one displayed.   Thus,  multiple  ^r's  can  be
  2067.             used to access the desired line.  The search  can  be  made  to
  2068.             find only lines which have a matching  prefix,  or  lines  that
  2069.             have a matching substring; this  behavior  is  changeable  with
  2070.             the options command.
  2071.  
  2072.             If the line is changed in any way, it  will  be  re-entered  at
  2073.             bottom of the history list as a new  command.   If  it  is  not
  2074.             edited, it will simply be  executed,  but  not  inserted  again
  2075.             into the history list (although this behaviour can  be  changed
  2076.             with the options command.
  2077.  
  2078.             The ^o key  is  useful  for  executing  a  series  of  commands
  2079.             multiple times.  Suppose your history list looks like this:
  2080.  
  2081.                1: echo $HISTSIZE
  2082.                2: date
  2083.                3: echo 'command 1'
  2084.                4: echo 'command 2'
  2085.                5: echo 'command 3'
  2086.  
  2087.             Use the ^p key or up  arrow  to  move  to  the  3rd  line.   By
  2088.             pressing the ^o key, that line is executed, and SKsh  remembers
  2089.             which line that was.  By pressing ^o again, the  next  line  is
  2090.             executed.  Upon reaching the end of the  list,  SKsh  moves  to
  2091.             the first line  upon  which  ^o  was  used.   In  this  manner,
  2092.             'command 1', 'command 2',  and  'command  3'  would  be  echoed
  2093.             repeatedly.  Using any other movement or editing  command  will
  2094.             cause SKsh to forget which line was the  first,  and  you  will
  2095.             have to move to it again.
  2096.  
  2097.             The ^u key causes the next command to be repeated  four  times.
  2098.             For example, pressing ^u followed by the '-' key  inserts  four
  2099.             dashes.  Pressing ^u followed by the delete  key  deletes  four
  2100.             characters.  The action of ^u is recursive;  two ^u's in a  row
  2101.             will repeat the next command 16 times.  Three would  repeat  64
  2102.             times.   Therefore,  to  insert  a  row  of  64   dashes,   use
  2103.             '^u^u^u-'.
  2104.  
  2105.  
  2106.  
  2107.  
  2108.  
  2109.           SKSH Amiga Shell            Page 32                 User's Guide
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.  
  2117.  
  2118.  
  2119.             The maximum line length in SKsh is currently  1023  characters.
  2120.             Attempting to enter lines longer than this  from  the  keyboard
  2121.             will result in an error message.
  2122.  
  2123.             If you press a function key, SKsh will examine the contents  of
  2124.             the variable with the same  name.   For  example,  pressing  f1
  2125.             would cause SKsh to look for a  variable  named  'f1',  and  if
  2126.             found, insert the text it contains as if you had typed it.   If
  2127.             the text ends in a  newline,  SKsh  will  execute  the  command
  2128.             immediately; otherwise, it will simply display it  for  editing
  2129.             or execution.  For example:
  2130.  
  2131.                [dh0:]: f1="echo testing"
  2132.  
  2133.             would would just display "echo testing"  when  f1  is  pressed,
  2134.             but:
  2135.  
  2136.                [dh0:]: f1="echo testing\n"
  2137.  
  2138.             would execute the command as well.
  2139.  
  2140.             <esc>. will insert the last parameter  of  the  previous  line.
  2141.             For example, suppose you have typed:
  2142.  
  2143.                [dh0:]: ll some_file_name
  2144.  
  2145.             Now, you can type:
  2146.  
  2147.                [dh0:]: rm
  2148.  
  2149.             and press <esc>., which will insert some_file_name:
  2150.  
  2151.                [dh0:]: rm some_file_name
  2152.  
  2153.             Similarly, <esc>/ will insert the "tail" of the previous  line;
  2154.             that is, all of the line except the first parameter.
  2155.  
  2156.             In addition to the interactive  editing  facilities,  a  single
  2157.             command can be executed with the  'history  -e'  command.   You
  2158.             can specify either a substring of  the  command,  its  absolute
  2159.             number, or its relative number  by  using  a  negative  offset.
  2160.             For  example,  given  the  above  history  list,  all  of   the
  2161.             following would echo 'command 2':
  2162.  
  2163.                [dh0:]: history -e 'd 2'
  2164.                [dh0:]: history -e 4
  2165.                [dh0:]: history -e -2
  2166.  
  2167.             The executed command is not placed at the end  of  the  history
  2168.             list (see the  options command).  For convenience, 'history -e'
  2169.             has been aliased to  '!'.   Also,  'history  -e  -1'  has  been
  2170.             aliased  to  '!!'  (similar  to  csh, except that in SKsh there
  2171.             must be a space  between  the  '!'  and  the  parameter).   For
  2172.             example,
  2173.  
  2174.  
  2175.           SKSH Amiga Shell            Page 33                 User's Guide
  2176.  
  2177.  
  2178.  
  2179.  
  2180.  
  2181.  
  2182.  
  2183.  
  2184.  
  2185.  
  2186.  
  2187.                [dh0:]: ! test      # last line containing 'test'
  2188.                [dh0:]: !!          # previous command
  2189.                [dh0:]: ! -2        # two commands back
  2190.                [dh0:]: ! 3         # command number 3
  2191.  
  2192.             If you type a command line that would wrap onto the next  line,
  2193.             SKsh will instead scroll the line 12  characters  to  the  left
  2194.             and let you continue typing.  If you move off  either  side  of
  2195.             the "sliding window", sksh will adjust  the  line  accordingly.
  2196.             If this behaviour does  not  appear  to  be  acting  correctly,
  2197.             check the value  of  the  COLUMNS and PNPC variables, described
  2198.             in the Reference Manual.  The COLUMNS variable  should  be  set
  2199.             to the number of  columns  in  the  current  window,  and  PNPC
  2200.             should be set to  the  number  of  non-printable  ANSI  control
  2201.             characters in the SKsh prompt (21 for the default prompt).   If
  2202.             either of these numbers are  wrong,  long  lines  will  display
  2203.             improperly.  (In  SKsh  1.2  or  later,  these  variables   are
  2204.             normally set automatically.) Also, SKsh  line  editing  can  be
  2205.             turned off  completely;  see  the  options command for details.
  2206.             In this case, no line scrolling is performed.  If  the  COLUMNS
  2207.             variable is set to less than 15, SKsh will get confused.
  2208.  
  2209.  
  2210.  
  2211.  
  2212.  
  2213.  
  2214.  
  2215.  
  2216.  
  2217.  
  2218.  
  2219.  
  2220.  
  2221.  
  2222.  
  2223.  
  2224.  
  2225.  
  2226.  
  2227.  
  2228.  
  2229.  
  2230.  
  2231.  
  2232.  
  2233.  
  2234.  
  2235.  
  2236.  
  2237.  
  2238.  
  2239.  
  2240.  
  2241.           SKSH Amiga Shell            Page 34                 User's Guide
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.  
  2249.  
  2250.  
  2251.           Filename Completion
  2252.  
  2253.             SKsh  supports  filename  completion  using  <esc><esc> or tab.
  2254.             For example, suppose your current  working  directory  contains
  2255.             the following files:
  2256.  
  2257.                my_file.c
  2258.                another_c_file.c
  2259.                this_is_a_long_filename
  2260.                test_file2
  2261.                test_file3
  2262.                picture.ham
  2263.                picture1.ham
  2264.                picture2.ham
  2265.  
  2266.             If SKsh command line editing is  turned  on  (see  the  options
  2267.             command), you can insert any file name into  the  command  line
  2268.             by typing part of the file name and  pressing  the  escape  key
  2269.             twice.  For example, suppose you typed:
  2270.  
  2271.                [dh0:]: cat ano
  2272.  
  2273.             and pressed <esc><esc>.  SKsh would fill in  the  rest  of  the
  2274.             file name for you:
  2275.  
  2276.                [dh0:]: cat another_c_file.c
  2277.  
  2278.             In fact, since 'a' is  enough  to  uniquely  specify  the  file
  2279.             name, you could have typed 'a<esc><esc>' for the  same  effect.
  2280.             In the case of  'test_file2'  and  'test_file3'  above,  typing
  2281.             'te' is not enough to uniquely specify the file, but SKsh  will
  2282.             help here too by filling in as much as it can:
  2283.  
  2284.                [dh0:]: echo te
  2285.  
  2286.             (press <esc><esc>)
  2287.  
  2288.                [dh0:]: echo test_file
  2289.  
  2290.             You would then have to type either '2' or  '3',  but  you  have
  2291.             still saved 7 characters of typing.
  2292.  
  2293.             Filename completion is useful not only to save typing,  but  to
  2294.             insure that you have not mis-typed the file name.  You can  use
  2295.             filename completion on paths, as well:
  2296.  
  2297.                [dh0:]: sys:S                      (press <esc><esc>)
  2298.                [dh0:]: sys:System/Fo              (type /Fo and <esc><esc)
  2299.                [dh0:]: sys:System/Format
  2300.  
  2301.             The tab key can also be used for  filename  completion  if  the
  2302.             proper option to SKsh is set (see the options command).
  2303.  
  2304.  
  2305.  
  2306.  
  2307.           SKSH Amiga Shell            Page 35                 User's Guide
  2308.  
  2309.  
  2310.  
  2311.  
  2312.  
  2313.  
  2314.  
  2315.  
  2316.  
  2317.             By default, case is not  significant  in  filename  completion,
  2318.             although this behavior can be changed with the option  command.
  2319.             Also,  if  file  name  mapping  is  enabled  (see  the  options
  2320.             command), it will be performed on the  current  file  name,  if
  2321.             applicable.    Thus,   '/System/Fo'   will   be   changed    to
  2322.             ':System/Format' (notice  the  first  slash  is  changed  to  a
  2323.             colon).
  2324.  
  2325.             In SKsh  1.1  or  later,  there  are  two  additional  filename
  2326.             completion  features.   You  can  type   a   partial   filename
  2327.             (optionally using wildcard patterns), press  <esc>=,  and  SKsh
  2328.             will list all matching files as if an '*' were appended to  the
  2329.             filename you typed.  It will the re-display your  command  line
  2330.             so you can continue typing:
  2331.  
  2332.                [dh0:]: show pic                 ( press <esc>=)
  2333.                   1) picture.ham
  2334.                   2) picture1.ham
  2335.                   3) picture2.ham
  2336.                [dh0:]: show pic
  2337.  
  2338.             You can then continue typing, but  you  can  see  the  matching
  2339.             files.  This is useful when you have typed part of  a  command,
  2340.             and  then  think  'Hmm,  what  was  that  file  called?'.   The
  2341.             filename you type can contain wilcard patterns, as well.
  2342.  
  2343.             Also in SKsh 1.1 or later, <esc>*  will  insert  matching  file
  2344.             names in the command line.  Again,  given  the  above  example,
  2345.             you could type
  2346.  
  2347.                [dh0:]: show *.ham
  2348.  
  2349.             and press <esc>*.  SKsh  will  re-write  the  command  line  as
  2350.             follows:
  2351.  
  2352.                [dh0:]: show picture.ham picture1.ham picture2.ham
  2353.  
  2354.             Using <esc>*, the pattern must match the  files  exactly;  SKsh
  2355.             does not append a '*' for you as it does with <esc>=.
  2356.  
  2357.             SKsh is, I believe, the first Amiga  shell  to  offer  filename
  2358.             completion.  You'll find it  addictive.   It  works  best  with
  2359.             hard or ram disks, since the directory seek speed is faster.
  2360.  
  2361.  
  2362.  
  2363.  
  2364.  
  2365.  
  2366.  
  2367.  
  2368.  
  2369.  
  2370.  
  2371.  
  2372.  
  2373.           SKSH Amiga Shell            Page 36                 User's Guide
  2374.  
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380.  
  2381.  
  2382.  
  2383.           Index to Users's Guide
  2384.  
  2385.             $#                          7, 18-19, 27
  2386.             $(                          3, 7, 14, 18, 21-22, 24
  2387.             $*                          18-19
  2388.             $0                          19
  2389.             $1                          18-19
  2390.             $2                          7, 19
  2391.             ( )                         3, 7, 14, 28
  2392.             -a                          10, 17-18, 20, 26
  2393.             -d fspec                    26
  2394.             -eq                         18, 26
  2395.             -f fspec                    26
  2396.             -gt                         6, 26
  2397.             -le                         26-27
  2398.             -lt                         6, 23, 26
  2399.             -n string                   26
  2400.             -ne                         26-27
  2401.             -o                          18, 26
  2402.             -r fspec                    26
  2403.             -s fspec                    26
  2404.             -w fspec                    26
  2405.             -x fspec                    26
  2406.             -z string                   26
  2407.             <esc><esc>                  3, 34
  2408.             alias                       2-3, 6-7, 17-20, 28, 30, 33
  2409.             append                      4, 11, 30
  2410.             assignment                  13, 22
  2411.             backspace                   31
  2412.             backticks                   21
  2413.             blanks                      15, 30
  2414.             boolean operators           26
  2415.             character class             16
  2416.             COLUMNS                     33
  2417.             Command Substitution        2-3, 7, 21-22, 24
  2418.             comment                     10, 30
  2419.             comparison operators        26
  2420.             Control Structures          2-3, 6-7, 23-25
  2421.             Copyright                   1-2, 4, 8-9, 17
  2422.             csh                         5, 33
  2423.             curly braces                18
  2424.             current working directory   10, 29, 34
  2425.             do                          2-6, 8-16, 18-20, 22, 24-31, 33
  2426.             done                        2, 6, 11-12, 18, 22, 24-25, 27-28
  2427.             dot                         29
  2428.             double quotes               13, 15
  2429.             down arrow                  31
  2430.             echo                        5-7, 11-12,  14-16,  18-20,  22-25,
  2431.                                         27-29, 31-34
  2432.             elif                        2, 18, 23
  2433.             else                        2, 9, 18, 23-24
  2434.             emacs                       3, 6, 10, 29
  2435.             enumerated characters       16
  2436.             esc-b                       31
  2437.  
  2438.  
  2439.           SKSH Amiga Shell            Page 37                 User's Guide
  2440.  
  2441.  
  2442.  
  2443.  
  2444.  
  2445.  
  2446.  
  2447.  
  2448.  
  2449.             esc-f                       31
  2450.             excellence!                 8, 29
  2451.             executable                  26
  2452.             Executing Commands          2, 10
  2453.             expr                        2, 7, 18, 21, 23-27
  2454.             extending SKsh              18
  2455.             fi                          2-4, 6-7, 9, 11-32, 34-35
  2456.             File Name Mapping           2, 16, 29, 35
  2457.             Filename Completion         2-3, 31, 34-35
  2458.             for                         1-26, 28-35
  2459.             force                       20
  2460.             function                    2-3, 6-7, 17-22, 25, 27-28, 30-32
  2461.             function name               19
  2462.             functions                   2-3, 7, 17-19, 28, 30
  2463.             history                     2-3, 5, 7, 10, 31-33
  2464.             HISTSIZE                    31-32
  2465.             I/O Redirection             2-3, 11
  2466.             if                          2, 4, 6-7, 9-10, 12-16, 18-21,  23-
  2467.                                         30, 32-35
  2468.             IFS                         15
  2469.             inc                         4, 6-8, 12-14, 16-17, 22,  25,  27,
  2470.                                         30, 34-35
  2471.             index parameters            25
  2472.             input                       6, 11, 19, 24, 28
  2473.             internal field separator    15
  2474.             ksh                         1, 3, 5-6, 9, 13, 19
  2475.             Lattice                     8-9
  2476.             line editing                2-3, 31, 33-34
  2477.             list of aliases             17
  2478.             local                       3, 7, 18, 28, 30
  2479.             more input                  19
  2480.             newlines                    12, 15, 30
  2481.             number of parameters        15, 19
  2482.             parameter list              19
  2483.             Parameter Substitution      2, 15, 21
  2484.             parameters                  3, 6-7, 14-20, 25, 27
  2485.             path                        16, 18, 21-22, 29-30, 34
  2486.             Pipe Lines                  2, 12
  2487.             pipeline                    6
  2488.             PNPC                        33
  2489.             Priority                    2, 20
  2490.             range of characters         16
  2491.             read                        6, 9, 11-12, 21, 24, 26, 28, 30
  2492.             readable                    26
  2493.             return code                 23-24, 26
  2494.             reverse search              31-32
  2495.             right arrow                 31
  2496.             secondary SKsh prompt string     19
  2497.             semicolon                   10
  2498.             set of characters           16, 21
  2499.             sh                          1-25, 27-35
  2500.             shift                       18-19
  2501.             simple command              6, 11-12
  2502.             simple operators            26
  2503.  
  2504.  
  2505.           SKSH Amiga Shell            Page 38                 User's Guide
  2506.  
  2507.  
  2508.  
  2509.  
  2510.  
  2511.  
  2512.  
  2513.  
  2514.  
  2515.             single parameter            15
  2516.             single quotes               13, 15
  2517.             slash                       13, 29, 35
  2518.             sleep                       10, 24
  2519.             slow script files           18
  2520.             string                      2, 10, 13-16, 19,  21,  26,  30-31,
  2521.                                         33
  2522.             sub shell                   28
  2523.             subshell                    6, 28, 30
  2524.             tabs                        15
  2525.             test expression             2, 23-24, 26-27
  2526.             then                        2, 6, 18, 23-24, 26-27, 29, 31, 34
  2527.             token                       21
  2528.             unalias                     17
  2529.             up arrow                    31-32
  2530.             variable                    2-3, 7, 13-15,  18-19,  21-22,  24-
  2531.                                         25, 27-33
  2532.             which                       3, 6-8, 13-16, 20-22, 24,  26,  29,
  2533.                                         32
  2534.             while                       2, 6, 11, 18, 24-27
  2535.             white space                 13, 15
  2536.             Wildcards                   2-3, 8, 16
  2537.             writable                    26
  2538.             [ ]                         16, 26
  2539.             ^a                          31
  2540.             ^b                          31
  2541.             ^d                          31
  2542.             ^e                          5, 31
  2543.             ^f                          31
  2544.             ^h                          31
  2545.             ^k                          31
  2546.             ^l                          5, 31
  2547.             ^m                          31
  2548.             ^n                          31
  2549.             ^o                          31-32
  2550.             ^p                          31-32
  2551.             ^r                          31-32
  2552.             { }                         28
  2553.  
  2554.  
  2555.  
  2556.  
  2557.  
  2558.  
  2559.  
  2560.  
  2561.  
  2562.  
  2563.  
  2564.  
  2565.  
  2566.  
  2567.  
  2568.  
  2569.  
  2570.  
  2571.           SKSH Amiga Shell            Page 39                 User's Guide
  2572.  
  2573.  
  2574.  
  2575.